package bf.program;

import org.objectweb.asm.MethodVisitor;


public class CodeBlock extends CompiableCode {

//	public void compile() {
//		for(ProgElement pe: progElements){
//			if(pe instanceof Compiable){
//				Compiable cb = (Compiable)pe;
//				cb.compile();
//			}
//		}
//	}

	ProgElement[] progElements;
	public CodeBlock(ProgElement[] peList) {
		super();
		this.progElements = peList;
	}

	public ProgElement[] getProgElements() {
		return progElements;
	}

	public void setProgElements(ProgElement[] progElements) {
		this.progElements = progElements;
	}
	
	@Override
	public void genCode(MethodVisitor mv) {
		for(ProgElement pe: progElements){
			Compiable cmp = (Compiable)pe;
			if(pe instanceof CodeBlock) {
//				genCall(mv, cmp.getCompiled());
				cmp.genCode(mv);
			} else if (pe instanceof CommandBlock){
//				genCall(mv, cmp.getCompiled());
				cmp.genCode(mv);
			} else if (pe instanceof Loop) {
				genCall(mv, cmp.getCompiled());
//				cmp.genCode(mv);
			}
		}
	}

	@Override
	public void iexecute(State state) {
		for(ProgElement pe: progElements) {
			pe.execute(state);
		}
	}

}
